package com.lz.quickstart;

import rx.Observable;
import rx.Scheduler;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * First..
 *
 * @author Lizhong
 * @date 2019/8/30
 */
public class First {
    public static void hello(String... names) {
        Observable.from(names).subscribe(new Action1<String>() {

            @Override
            public void call(String s) {
                System.out.println("Hello " + s + "!");
            }

        });
    }

    public static void method01() {
        Observable<String> o = Observable.from(new String[]{"a", "b", "c"});
        Subscription subscribe = o.first().subscribe(System.out::println);

        Integer[] list = {5, 6, 7, 8};
        Observable<Integer> integerObservable = Observable.from(list);
        integerObservable.filter(val -> val % 2 == 0).subscribe(System.out::println);

        Observable<String> oneObject = Observable.just("one object");
        oneObject.timestamp().subscribe(System.out::println);


    }
    public void method02(){
        Scheduler.Worker worker = Schedulers.newThread().createWorker();
        worker.schedule(new Action0() {

            @Override
            public void call() {
                System.out.println("haha");
                // recurse until unsubscribed (schedule will do nothing if unsubscribed)
                worker.schedule(this);
            }

        });
// some time later...
        worker.unsubscribe();
    }

    public static void main(String[] args) {
        hello("张三");
        method01();
    }
}
